package com.lg.concurrent.base;


/**
 * current thread name
 */
public class ThreadName {
    static class ActionThread extends Thread{
        String name;
        ActionThread(String name){
            this.name = name;
            System.out.println(name+"--construction--begin");
            System.out.println(name+"--construction--Thread.currentThread().getName(): "+Thread.currentThread().getName());
            System.out.println(name+"--construction--this.getName(): "+this.getName());
            System.out.println(name+"--construction--this.isAlive(): "+this.isAlive());

            System.out.println(name+"--construction--this.currentThread().getName(): "+this.currentThread().getName());
            System.out.println(name+"--construction--this.currentThread().isAlive(): "+this.currentThread().isAlive());
            System.out.println(name+"--construction--this.getId(): "+this.getId());

            System.out.println(name+"--construction--end");
        }

        @Override
        public void run() {
            System.out.println(name+"--run--begin");
            System.out.println(name+"--run--Thread.currentThread().getName(): "+Thread.currentThread().getName());
            System.out.println(name+"--run--this.getName():  "+this.getName());
            System.out.println(name+"--run--this.isAlive():  "+this.isAlive());

            System.out.println(name+"--run--this.currentThread().getName(): "+this.currentThread().getName());
            System.out.println(name+"--run--this.currentThread().isAlive(): "+this.currentThread().isAlive());
            System.out.println(name+"--run--this.getId(): "+this.getId());
            System.out.println(name+"--run--end");

        }
    }


    public static void main(String[] args) {

        /**
         * test1
         */
//        System.out.println("main--thread-name: "+ Thread.currentThread().getName());
//        ActionThread actionThread = new ActionThread("1111");
//        actionThread.start();
//
//        ActionThread actionThread2 = new ActionThread("222");
//        actionThread2.start();

        /**
         * test2
         *
         * 1111--construction--begin
         * 1111--construction--Thread.currentThread().getName(): main
         * 1111--construction--this.getName(): Thread-0
         * 1111--construction--this.isAlive(): false
         * 1111--construction--end
         * main--get-name: Thread-0
         * main--is-alive: false
         * main--get-name: ag
         * main--is-alive: true
         * 1111--run--begin
         * 1111--run--Thread.currentThread().getName(): ag
         * 1111--run--this.getName():  ag
         * 1111--run--this.isAlive():  true
         * 1111--run--end
         *
         * Thread.currentThread().getName() 和 this.getName() 随着actionThread.setName("ag"); 变化而变化
         *
         */
        System.out.println("main-thread0--id: "+ Thread.currentThread().getId());
        ActionThread actionThread = new ActionThread("1111");
        System.out.println("main--get-name: "+ actionThread.getName());
        System.out.println("main--is-alive: "+ actionThread.isAlive());
        System.out.println("main--getId(): "+ actionThread.getId());
        actionThread.start();
        actionThread.setName("ag");
        System.out.println("main--get-name: "+ actionThread.getName());
        System.out.println("main--getId(): "+ actionThread.getId());





    }
}
